package generic;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CovariantReturnType {

	static class Parent<T extends Parent<T>> implements Comparable<T>{

		@Override
		public int compareTo(T o) {
			System.out.println("parent compareTo");
			return 0;
		}
		
	}
	
	static class Child extends Parent<Child>{
		
		@Override
 		public int compareTo(Child o) {
			System.out.println("child compareTo");
			return 0;
		}
	};
	
	static <T extends Comparable<T>> void sort(T a,T b){
		a.compareTo(b);
	}
	
	public static void main(String[] args) {
		
		Parent p = new Parent();
		CovariantReturnType.<Parent>sort(p, p);
		
		Child c = new Child();
		CovariantReturnType.<Child>sort(c, c);
		
		
		List<Parent> list1 = new ArrayList<Parent>();
		list1.add(p);
		list1.add(p);
		Collections.sort(list1);
		List<Child> list2 = new ArrayList<Child>();
		list2.add(c);
		list2.add(c);
		Collections.sort(list2);
		
		
	}
	
}
